<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <title>Virus Bacteria Interaction Prediction</title>
    <link rel="stylesheet" type="text/css" href="lib/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/jquery-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/jqwidgets/styles/jqx.base.css" />
    <link rel="stylesheet" type="text/css" href="css/styles.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/custom_new.css">
    
    <script type="text/javascript" src="lib/js/d3.js"></script>
    <script type="text/javascript" src="lib/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="lib/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="lib/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="lib/js/math.min.js"></script>
    <script type="text/javascript" src="lib/jqwidgets/jqx-all.js"></script>
</head>


<body>
	
<div id="tooltip1" class="hidden"><p><span id="value"></div>

<div id="container-id-1" style="width: 1670px; height: 1000px; clear: both;">
	<div class="sidebar_wrapper" style="float: left; width: 300px; height: 1000px; overflow: hidden; display: block; border-right: 1px solid grey;">
		<div class="title_section">
			<img class="title_image" src="logo.jpg" alt="" style="width: 290px; margin-left: 2px; margin-top: 5px;">
		</div>
		
		<div class="reorder_section" style="margin: 1px; margin-top: 10px; padding:2px; font-size: 11px; border: 0.5px solid grey;">
			<div id='jqxWidget'><label>Select the Virus for visualization: </label><div id="listbox"></div></div>
			
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="topAmount"># of top Hosts: </label><input type="text" value="25" id="topAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="topSlider" style="width: 290px;"></div>
			</div>
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="cutoffAmount">Max distance &lt;= </label><input type="text" value="1" id="cutoffAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="cutoffSlider" style="width: 290px;"></div>
			</div>
			<div class="btn-group gene_search_button" data-toggle="buttons" style="margin-top: 10px;">
				<div><button id="okBtn" class="sidebar_text btn btn-primary submit_gene_button" type="button" disabled="true" onclick="updateData()" style="float: left; padding-top: 6px; padding-bottom: 6px;">OK</button></div>
			</div>
		</div>
	</div>
	<div id="vizcontainer" style="float: left; width: 1000px; height: 800px; overflow: auto; ">
		<svg id="heatCanvas"></svg> 
	</div>
	<div style="float: left;margin-left: 20px; margin-top: 50px; ">
		<div><b>Consensus Information</b></div>
		<div id="consensusSuperkingdom"></div>
		<div id="consensusPhylum"></div>
		<div id="consensusClass"></div>
		<div id="consensusOrder"></div>
		<div id="consensusFamily"></div>
		<div id="consensusGenus"></div>
		<div id="consensusSpecies"></div>
	</div>
</div>


<footer id="footer_div" class="footer navbar-fixed-bottom">
    <div class="row"><div class="col-xs-12 footer_section"><p class="text-muted">Copyright (C) 2016 Yang Lu &lt;<a href="mailto:ylu465@usc.edu">ylu465@usc.edu</a>&gt; @ Computational and Molecular Biology, Department of Biological Science, University of Southern California, LA, CA 90089, USA </p></div></div>
</footer>

<script type="text/javascript">
	var margin = {top: 200, right: 10, bottom: 10, left: 200};
   var colors = ['#91003F','#9B1A53','#A63467','#B14F7C','#BB6990','#C684A4','#D19EB9','#DBB9CD','#E6D3E1','#F1EEF6','#FFFFFF'];
   
   var virusNameIdxMap = new Object(), hostNameIdxMap = new Object();   
   var topHostNum = 50, cutoff = 1;
   var checkedVirusIdxArr = [], checkedVirusArr = [], hostArr = [], edgeData =[];
   var virusNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var hostNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var virusHostMat = [[0,0.50597,0.567482,0.586996,0.557258,0.286565,0.593015,0.674591,0.793882,0.668978,0.319678,0.521869,0.4937,0.802473,0.520308,0.618762,0.548995,1.19675,0.675118,0.596748,0.755883,0.648894,0.505789,0.487067,0.547876,0.535699,1.01641,0.568158,0.57484,1.13186,0.567405,0.580709,0.476038,0.491366,0.433326,0.844141,0.511293,0.80749,0.572666],
[0.50597,0,0.607882,0.623378,0.524345,0.501186,0.733246,0.779135,0.821494,0.658282,0.525596,0.588333,0.493104,0.923543,0.600321,0.72593,0.71948,1.27261,0.70337,0.754304,0.801528,0.67863,0.57221,0.488876,0.612887,0.603392,1.12784,0.643582,0.566972,1.2113,0.569721,0.729253,0.506044,0.635874,0.488154,0.90215,0.527098,0.848038,0.698102],
[0.567482,0.607882,0,0.497806,0.60892,0.566316,0.720526,0.775264,0.825318,0.69454,0.587405,0.607421,0.596184,0.927807,0.665456,0.702909,0.71925,1.24396,0.627734,0.693549,0.736157,0.699732,0.582412,0.574139,0.648133,0.663947,1.1226,0.715575,0.591644,1.18294,0.637718,0.714309,0.587819,0.654193,0.577361,0.888469,0.53061,0.826835,0.703166],
[0.586996,0.623378,0.497806,0,0.59375,0.593475,0.794712,0.692137,0.759882,0.636636,0.642938,0.647908,0.64208,0.842789,0.754821,0.615543,0.694091,1.15232,0.683155,0.727641,0.666924,0.752125,0.61513,0.620565,0.698006,0.658289,1.02337,0.669268,0.654292,1.08881,0.728772,0.799438,0.624783,0.659071,0.606473,0.779708,0.561164,0.721415,0.625375],
[0.557258,0.524345,0.60892,0.59375,0,0.543887,0.723927,0.704262,0.785965,0.58837,0.615446,0.624598,0.525175,0.819403,0.680915,0.634965,0.655776,1.16341,0.7354,0.76245,0.730894,0.713808,0.577587,0.513436,0.672702,0.6016,1.02144,0.615314,0.542526,1.10152,0.607057,0.730647,0.518848,0.576627,0.489381,0.828054,0.472487,0.776622,0.6331],
[0.286565,0.501186,0.566316,0.593475,0.543887,0,0.622714,0.708448,0.814369,0.662538,0.275583,0.520883,0.492607,0.840195,0.53006,0.667024,0.614264,1.24078,0.680445,0.622836,0.78967,0.645717,0.496093,0.486901,0.534019,0.522624,1.0382,0.570331,0.551597,1.17809,0.573469,0.610233,0.484307,0.524802,0.437621,0.872963,0.48964,0.84207,0.603988],
[0.593015,0.733246,0.720526,0.794712,0.723927,0.622714,0,0.931527,0.977979,0.944425,0.584718,0.671695,0.520082,0.969036,0.487288,0.853994,0.598024,1.32798,0.809343,0.73147,0.964976,0.782537,0.738281,0.554508,0.625431,0.808695,1.21603,0.833055,0.655497,1.27353,0.482981,0.0916512,0.539281,0.490547,0.580156,1.08739,0.652043,1.04684,0.826522],
[0.674591,0.779135,0.775264,0.692137,0.704262,0.708448,0.931527,0,0.788747,0.624641,0.799125,0.823992,0.806034,0.38386,0.952526,0.304447,0.537354,0.685673,0.888957,0.804908,0.561928,0.936459,0.74648,0.783114,0.878574,0.699649,0.598426,0.649916,0.869677,0.621858,0.937523,0.939967,0.807031,0.61765,0.682722,0.488234,0.76579,0.425786,0.501597],
[0.793882,0.821494,0.825318,0.759882,0.785965,0.814369,0.977979,0.788747,0,0.772927,0.859433,0.860139,0.830616,0.883386,0.94723,0.725517,0.792016,1.12354,0.902535,0.895538,0.795398,0.911749,0.800685,0.820633,0.913646,0.81468,1.05542,0.807472,0.874991,1.06622,0.913945,0.982297,0.84897,0.804784,0.788019,0.856681,0.803495,0.812498,0.779255],
[0.668978,0.658282,0.69454,0.636636,0.58837,0.662538,0.944425,0.624641,0.772927,0,0.757908,0.753839,0.742269,0.730552,0.897272,0.550536,0.737761,1.01952,0.847178,0.855687,0.649977,0.845629,0.687597,0.697627,0.822219,0.653744,0.89431,0.643977,0.778661,0.957338,0.851702,0.954804,0.734563,0.726336,0.655576,0.650292,0.667947,0.611522,0.606553],
[0.319678,0.525596,0.587405,0.642938,0.615446,0.275583,0.584718,0.799125,0.859433,0.757908,0,0.517072,0.506662,0.925764,0.47188,0.752384,0.636297,1.31257,0.667341,0.610676,0.861057,0.643236,0.527913,0.519678,0.514451,0.59116,1.13838,0.63691,0.560928,1.25091,0.544106,0.564272,0.504904,0.543601,0.476332,0.961517,0.524085,0.93052,0.688476],
[0.521869,0.588333,0.607421,0.647908,0.624598,0.520883,0.671695,0.823992,0.860139,0.753839,0.517072,0,0.564267,0.961156,0.570488,0.753827,0.688527,1.30257,0.708164,0.6788,0.831938,0.653388,0.528697,0.554729,0.56084,0.599293,1.17979,0.647778,0.628331,1.23682,0.600988,0.659749,0.562002,0.623424,0.559913,0.954647,0.568078,0.917606,0.744222],
[0.4937,0.493104,0.596184,0.64208,0.525175,0.492607,0.520082,0.806034,0.830616,0.742269,0.506662,0.564267,0,0.920462,0.484616,0.744524,0.648661,1.28269,0.697398,0.722834,0.808143,0.668813,0.580508,0.331257,0.565863,0.642592,1.14363,0.67789,0.514433,1.22405,0.407713,0.515785,0.377214,0.532676,0.416763,0.950616,0.490983,0.902717,0.704664],
[0.802473,0.923543,0.927807,0.842789,0.819403,0.840195,0.969036,0.38386,0.883386,0.730552,0.925764,0.961156,0.920462,0,1.07466,0.390651,0.563336,0.567776,1.05578,0.927998,0.720826,1.06599,0.897926,0.894927,1.00835,0.82226,0.480861,0.75505,1.00548,0.511449,1.04226,0.984344,0.923918,0.637429,0.79003,0.547107,0.90696,0.525367,0.542793],
[0.520308,0.600321,0.665456,0.754821,0.680915,0.53006,0.487288,0.952526,0.94723,0.897272,0.47188,0.570488,0.484616,1.07466,0,0.905763,0.71417,1.4263,0.710476,0.688727,0.966661,0.664545,0.631079,0.517532,0.534544,0.716934,1.29214,0.769437,0.596947,1.36605,0.428152,0.458256,0.47253,0.62775,0.538453,1.10874,0.584171,1.06845,0.861639],
[0.618762,0.72593,0.702909,0.615543,0.634965,0.667024,0.853994,0.304447,0.725517,0.550536,0.752384,0.753827,0.744524,0.390651,0.905763,0,0.432569,0.708603,0.852359,0.740224,0.513266,0.876042,0.690172,0.711892,0.826172,0.634403,0.65883,0.572648,0.834025,0.629904,0.87571,0.864439,0.751577,0.522262,0.615513,0.455008,0.712592,0.361508,0.426131],
[0.548995,0.71948,0.71925,0.694091,0.655776,0.614264,0.598024,0.537354,0.792016,0.737761,0.636297,0.688527,0.648661,0.563336,0.71417,0.432569,0,0.920555,0.827136,0.632183,0.686201,0.813723,0.685933,0.637601,0.71797,0.661757,0.861663,0.635788,0.736305,0.844151,0.713661,0.606086,0.655379,0.337775,0.539599,0.710922,0.65777,0.682148,0.541762],
[1.19675,1.27261,1.24396,1.15232,1.16341,1.24078,1.32798,0.685673,1.12354,1.01952,1.31257,1.30257,1.28269,0.567776,1.4263,0.708603,0.920555,0,1.35233,1.24145,0.911882,1.38247,1.24287,1.25318,1.35229,1.16915,0.594308,1.08876,1.34582,0.172234,1.38856,1.3433,1.28697,1.04043,1.16369,0.709159,1.25963,0.636453,0.919655],
[0.675118,0.70337,0.627734,0.683155,0.7354,0.680445,0.809343,0.888957,0.902535,0.847178,0.667341,0.708164,0.697398,1.05578,0.710476,0.852359,0.827136,1.35233,0,0.745745,0.851397,0.739365,0.707612,0.715458,0.709322,0.793776,1.23543,0.816046,0.661241,1.2985,0.742916,0.802286,0.691097,0.759693,0.691555,1.02784,0.647697,0.965909,0.846591],
[0.596748,0.754304,0.693549,0.727641,0.76245,0.622836,0.73147,0.804908,0.895538,0.855687,0.610676,0.6788,0.722834,0.927998,0.688727,0.740224,0.632183,1.24145,0.745745,0,0.856084,0.746408,0.709811,0.732365,0.669913,0.719823,1.13852,0.734836,0.77101,1.18011,0.744591,0.712756,0.701063,0.664821,0.677162,0.951373,0.696658,0.908836,0.758262],
[0.755883,0.801528,0.736157,0.666924,0.730894,0.78967,0.964976,0.561928,0.795398,0.649977,0.861057,0.831938,0.808143,0.720826,0.966661,0.513266,0.686201,0.911882,0.851397,0.856084,0,0.935897,0.769829,0.790087,0.904051,0.751418,0.904303,0.727753,0.870102,0.843971,0.941155,0.970418,0.822034,0.736469,0.731632,0.63737,0.756298,0.517097,0.658835],
[0.648894,0.67863,0.699732,0.752125,0.713808,0.645717,0.782537,0.936459,0.911749,0.845629,0.643236,0.653388,0.668813,1.06599,0.664545,0.876042,0.813723,1.38247,0.739365,0.746408,0.935897,0,0.680199,0.660837,0.659544,0.745378,1.25749,0.77039,0.711525,1.32079,0.692403,0.77199,0.656937,0.763211,0.670167,1.04626,0.680263,1.02113,0.840229],
[0.505789,0.57221,0.582412,0.61513,0.577587,0.496093,0.738281,0.74648,0.800685,0.687597,0.527913,0.528697,0.580508,0.897926,0.631079,0.690172,0.685933,1.24287,0.707612,0.709811,0.769829,0.680199,0,0.565992,0.581883,0.536913,1.10924,0.578111,0.621062,1.17134,0.632258,0.729781,0.55656,0.645156,0.547707,0.8802,0.55511,0.83481,0.677558],
[0.487067,0.488876,0.574139,0.620565,0.513436,0.486901,0.554508,0.783114,0.820633,0.697627,0.519678,0.554729,0.331257,0.894927,0.517532,0.711892,0.637601,1.25318,0.715458,0.732365,0.790087,0.660837,0.565992,0,0.573879,0.622365,1.11243,0.66311,0.541969,1.19188,0.431424,0.556579,0.400247,0.537116,0.414013,0.907352,0.504562,0.86586,0.679798],
[0.547876,0.612887,0.648133,0.698006,0.672702,0.534019,0.625431,0.878574,0.913646,0.822219,0.514451,0.56084,0.565863,1.00835,0.534544,0.826172,0.71797,1.35229,0.709322,0.669913,0.904051,0.659544,0.581883,0.573879,0,0.64239,1.22432,0.68407,0.622109,1.28918,0.57622,0.609186,0.553151,0.659354,0.573338,1.01277,0.608448,0.977344,0.787893],
[0.535699,0.603392,0.663947,0.658289,0.6016,0.522624,0.808695,0.699649,0.81468,0.653744,0.59116,0.599293,0.642592,0.82226,0.716934,0.634403,0.661757,1.16915,0.793776,0.719823,0.751418,0.745378,0.536913,0.622365,0.64239,0,1.02159,0.554941,0.695042,1.09775,0.732678,0.804055,0.638377,0.661414,0.578344,0.806025,0.608762,0.777903,0.634884],
[1.01641,1.12784,1.1226,1.02337,1.02144,1.0382,1.21603,0.598426,1.05542,0.89431,1.13838,1.17979,1.14363,0.480861,1.29214,0.65883,0.861663,0.594308,1.23543,1.13852,0.904303,1.25749,1.10924,1.11243,1.22432,1.02159,0,0.96907,1.19187,0.604865,1.25284,1.23144,1.14186,0.909409,1.011,0.674855,1.11595,0.714664,0.766125],
[0.568158,0.643582,0.715575,0.669268,0.615314,0.570331,0.833055,0.649916,0.807472,0.643977,0.63691,0.647778,0.67789,0.75505,0.769437,0.572648,0.635788,1.08876,0.816046,0.734836,0.727753,0.77039,0.578111,0.66311,0.68407,0.554941,0.96907,0,0.746959,1.01141,0.779444,0.828998,0.680486,0.650454,0.597428,0.753347,0.651459,0.715795,0.609631],
[0.57484,0.566972,0.591644,0.654292,0.542526,0.551597,0.655497,0.869677,0.874991,0.778661,0.560928,0.628331,0.514433,1.00548,0.596947,0.834025,0.736305,1.34582,0.661241,0.77101,0.870102,0.711525,0.621062,0.541969,0.622109,0.695042,1.19187,0.746959,0,1.2917,0.541341,0.654552,0.535832,0.613727,0.522336,1.01928,0.455328,0.975173,0.791083],
[1.13186,1.2113,1.18294,1.08881,1.10152,1.17809,1.27353,0.621858,1.06622,0.957338,1.25091,1.23682,1.22405,0.511449,1.36605,0.629904,0.844151,0.172234,1.2985,1.18011,0.843971,1.32079,1.17134,1.19188,1.28918,1.09775,0.604865,1.01141,1.2917,0,1.33296,1.28753,1.22949,0.982211,1.10274,0.652019,1.1994,0.561673,0.852607],
[0.567405,0.569721,0.637718,0.728772,0.607057,0.573469,0.482981,0.937523,0.913945,0.851702,0.544106,0.600988,0.407713,1.04226,0.428152,0.87571,0.713661,1.38856,0.742916,0.744591,0.941155,0.692403,0.632258,0.431424,0.57622,0.732678,1.25284,0.779444,0.541341,1.33296,0,0.469813,0.424649,0.605284,0.505537,1.08852,0.536475,1.03514,0.83344],
[0.580709,0.729253,0.714309,0.799438,0.730647,0.610233,0.0916512,0.939967,0.982297,0.954804,0.564272,0.659749,0.515785,0.984344,0.458256,0.864439,0.606086,1.3433,0.802286,0.712756,0.970418,0.77199,0.729781,0.556579,0.609186,0.804055,1.23144,0.828998,0.654552,1.28753,0.469813,0,0.531488,0.505026,0.578355,1.10211,0.648879,1.05588,0.833626],
[0.476038,0.506044,0.587819,0.624783,0.518848,0.484307,0.539281,0.807031,0.84897,0.734563,0.504904,0.562002,0.377214,0.923918,0.47253,0.751577,0.655379,1.28697,0.691097,0.701063,0.822034,0.656937,0.55656,0.400247,0.553151,0.638377,1.14186,0.680486,0.535832,1.22949,0.424649,0.531488,0,0.564677,0.431729,0.949089,0.506194,0.906102,0.718218],
[0.491366,0.635874,0.654193,0.659071,0.576627,0.524802,0.490547,0.61765,0.804784,0.726336,0.543601,0.623424,0.532676,0.637429,0.62775,0.522262,0.337775,1.04043,0.759693,0.664821,0.736469,0.763211,0.645156,0.537116,0.659354,0.661414,0.909409,0.650454,0.613727,0.982211,0.605284,0.505026,0.564677,0,0.456352,0.796117,0.564957,0.759189,0.549275],
[0.433326,0.488154,0.577361,0.606473,0.489381,0.437621,0.580156,0.682722,0.788019,0.655576,0.476332,0.559913,0.416763,0.79003,0.538453,0.615513,0.539599,1.16369,0.691555,0.677162,0.731632,0.670167,0.547707,0.414013,0.573338,0.578344,1.011,0.597428,0.522336,1.10274,0.505537,0.578355,0.431729,0.456352,0,0.831686,0.483321,0.787872,0.612412],
[0.844141,0.90215,0.888469,0.779708,0.828054,0.872963,1.08739,0.488234,0.856681,0.650292,0.961517,0.954647,0.950616,0.547107,1.10874,0.455008,0.710922,0.709159,1.02784,0.951373,0.63737,1.04626,0.8802,0.907352,1.01277,0.806025,0.674855,0.753347,1.01928,0.652019,1.08852,1.10211,0.949089,0.796117,0.831686,0,0.906186,0.460366,0.617645],
[0.511293,0.527098,0.53061,0.561164,0.472487,0.48964,0.652043,0.76579,0.803495,0.667947,0.524085,0.568078,0.490983,0.90696,0.584171,0.712592,0.65777,1.25963,0.647697,0.696658,0.756298,0.680263,0.55511,0.504562,0.608448,0.608762,1.11595,0.651459,0.455328,1.1994,0.536475,0.648879,0.506194,0.564957,0.483321,0.906186,0,0.859012,0.69465],
[0.80749,0.848038,0.826835,0.721415,0.776622,0.84207,1.04684,0.425786,0.812498,0.611522,0.93052,0.917606,0.902717,0.525367,1.06845,0.361508,0.682148,0.636453,0.965909,0.908836,0.517097,1.02113,0.83481,0.86586,0.977344,0.777903,0.714664,0.715795,0.975173,0.561673,1.03514,1.05588,0.906102,0.759189,0.787872,0.460366,0.859012,0,0.6046],
[0.572666,0.698102,0.703166,0.625375,0.6331,0.603988,0.826522,0.501597,0.779255,0.606553,0.688476,0.744222,0.704664,0.542793,0.861639,0.426131,0.541762,0.919655,0.846591,0.758262,0.658835,0.840229,0.677558,0.679798,0.787893,0.634884,0.766125,0.609631,0.791083,0.852607,0.83344,0.833626,0.718218,0.549275,0.612412,0.617645,0.69465,0.6046,0]];
var superkingdomArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var phylumArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var classArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var orderArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var familyArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var genusArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var speciesArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var organismArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];

   for(var hostIdx=0; hostIdx<hostNameArr.length; hostIdx++) hostNameIdxMap[hostNameArr[hostIdx]] = hostIdx;
   for(var virusIdx=0; virusIdx<virusNameArr.length; virusIdx++) virusNameIdxMap[virusNameArr[virusIdx]] = virusIdx;
   console.log("phageToHost finish loading!");
   
   topHostNum = Math.min(25, hostNameArr.length);
   
   $(function() { $( "#topSlider" ).slider({ value:25, min: 1, max: 100, step: 1, slide: function( event, ui ) { $( "#topAmount" ).val( ui.value ); topHostNum = Math.min(ui.value, hostNameArr.length);  } }); }); 
   $(function() { $( "#cutoffSlider" ).slider({ value:1, min: 0, max: 1, step: 0.01, slide: function( event, ui ) { $( "#cutoffAmount" ).val( ui.value ); cutoff = ui.value; } }); });
   
   
   $("#listbox").jqxListBox({width: 290, height: 300, source: virusNameArr, checkboxes: true, filterable: true});
		$("#listbox").on('checkChange', function (event) {
			var items = $("#listbox").jqxListBox('getCheckedItems');
			checkedVirusIdxArr = []; checkedVirusArr = [];
			$.each(items, function (index) { checkedVirusIdxArr.push(this.index); checkedVirusArr.push(this.label); });
			
			if(checkedVirusIdxArr.length > 0) $("#okBtn").prop('disabled', false);
			else $("#okBtn").prop('disabled', true);
   });
   
   var host2organism = [], host2superkingdom = [], host2phylum = [], host2class = [], 
		host2order = [], host2family = [], host2genus = [], host2species = [];
   
   for(var t=0; t<hostNameArr.length; t++){
   		host2organism[hostNameArr[t]] = organismArr[t];
   		host2superkingdom[hostNameArr[t]] = superkingdomArr[t];
   		host2phylum[hostNameArr[t]] = phylumArr[t];
   		host2class[hostNameArr[t]] = classArr[t];
   		host2order[hostNameArr[t]] = orderArr[t];
   		host2family[hostNameArr[t]] = familyArr[t];
   		host2genus[hostNameArr[t]] = genusArr[t];
   		host2species[hostNameArr[t]] = speciesArr[t];
	}
	console.log("hostTaxonomy finish loading!");
	
	var minDist = 1, maxDist = 0, gap=0;
	for(var rowIdx=0; rowIdx<virusHostMat.length; rowIdx++) 
	{
		for(var colIdx=0; colIdx<virusHostMat[0].length; colIdx++)
		{
			if(virusHostMat[rowIdx][colIdx]<minDist) minDist = virusHostMat[rowIdx][colIdx];
			if(virusHostMat[rowIdx][colIdx]>maxDist) maxDist = virusHostMat[rowIdx][colIdx];
		}
	}
	minDist = Math.max(0,minDist-0.1); maxDist = Math.min(1,maxDist+0.1); gap = maxDist-minDist;
	var colorScale = d3.scale.quantile().domain([minDist,maxDist]).range(colors);

	function updateData() {
		topHostNum = Math.min(topHostNum, hostNameArr.length);

		var combinedArr = new Array(virusHostMat[checkedVirusIdxArr[0]].length).fill(0);
		for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) {
			for(var colIdx=0; colIdx<virusHostMat[checkedVirusIdxArr[rowIdx]].length; colIdx++) {
				combinedArr[colIdx] += virusHostMat[checkedVirusIdxArr[rowIdx]][colIdx];
			}
		}
		var tmpArr = combinedArr.slice(); 
		var thres = tmpArr.sort().slice(topHostNum-1,topHostNum);

		indiceArr = [];
		for(var colIdx=0; colIdx<combinedArr.length; colIdx++) {
			if(indiceArr.length >= topHostNum) break;
			if(combinedArr[colIdx] <= thres) { indiceArr.push({"idx":colIdx, "dist":combinedArr[colIdx] }); }
		}
		
		hostArr = []; edgeData =[];
		for(var colIdx=0; colIdx<indiceArr.length; colIdx++) {
			var realColIdx = indiceArr[colIdx].idx;
			hostArr.push(hostNameArr[realColIdx]);
			
			for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) { edgeData.push({"row":rowIdx, "col":hostArr.length-1, 
				"value":virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]<=cutoff?virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]:1}); }
		}
		
		pathArr = [];
		for(var colIdx=0; colIdx<hostArr.length; colIdx++) { pathArr.push([host2superkingdom[hostArr[colIdx]],host2phylum[hostArr[colIdx]],host2class[hostArr[colIdx]],host2order[hostArr[colIdx]],host2family[hostArr[colIdx]],host2genus[hostArr[colIdx]],host2species[hostArr[colIdx]]]); }
		//rootNode = 	convertToHierarchy(pathArr);
		//consensusArr = getConsensusTaxonomy(rootNode); 
		
		$("#consensusSuperkingdom").text("Superkingdom: "+getConsensusItem(pathArr,0));
		$("#consensusPhylum").text("Phylum: "+getConsensusItem(pathArr,1));
		$("#consensusClass").text("Class: "+getConsensusItem(pathArr,2));
		$("#consensusOrder").text("Order: "+getConsensusItem(pathArr,3));
		$("#consensusFamily").text("Family: "+getConsensusItem(pathArr,4));
		$("#consensusGenus").text("Genus: "+getConsensusItem(pathArr,5));
		$("#consensusSpecies").text("Species: "+getConsensusItem(pathArr,6));
		
		var cellSize = 25, legendElementWidth = cellSize*2, 
			width = Math.max(hostArr.length*cellSize, 1000 ), height = Math.max(checkedVirusIdxArr.length*cellSize, 700 );
		
		console.log();
		
		d3.selectAll(".canvasSvg").remove(); 
		var svg = d3.select("#heatCanvas").style("float", "left").attr("width", width).attr("height", height)
			.append("g").attr('class', "canvasSvg").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
			
		var rowLabels = svg.append("g").selectAll(".rowLabelg").data(checkedVirusArr).enter().append("text")
			.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "end").attr("transform", "translate(-6," + cellSize / 1.5 + ")")
      		.attr("class", function (d,i) { return "rowLabel mono r"+i;} ) ;
      		
      	var colLabels = svg.append("g").selectAll(".colLabelg").data(hostArr).enter().append("text")
      		.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "left").attr("transform", "translate("+cellSize/2 + ",-6) rotate (-90)")
      		.attr("class",  function (d,i) { return "colLabel mono c"+i;} );
      	
      	var heatMap = svg.append("g").attr("class","g3").selectAll(".cellg").data(edgeData).enter().append("rect")
			.attr("x", function(d) { return d.col * cellSize; }).attr("y", function(d) { return d.row * cellSize; })
        	.attr("class", function(d){return "cell cell-border cr"+(d.row)+" cc"+(d.col);})
        	.attr("width", cellSize).attr("height", cellSize).style("fill", function(d) { return colorScale(d.value); })
			.on("mouseover", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",true);
				d3.selectAll(".rowLabel").classed("text-highlight",function(r,ri){ return ri==d.row;});
				d3.selectAll(".colLabel").classed("text-highlight",function(c,ci){ return ci==d.col;});
				
				d3.select("#tooltip1").style("left", (d3.event.pageX+10) + "px").style("top", (d3.event.pageY-10) + "px")
					.html("Host Information: "+
						"<br> Superkingdom: "+ host2superkingdom[hostArr[d.col]] +
						"<br> Phylum: "+ host2phylum[hostArr[d.col]] +
						"<br> Class: "+ host2class[hostArr[d.col]] +
						"<br> Order: "+ host2order[hostArr[d.col]] +
						"<br> Family: "+ host2family[hostArr[d.col]] +
						"<br> Genus: "+ host2genus[hostArr[d.col]] +
						"<br> Species: "+ host2species[hostArr[d.col]] +
						"<br> Organism: "+ host2organism[hostArr[d.col]] +
						"<br> distance:"+d.value);  
                d3.select("#tooltip1").classed("hidden", false);
			})
			.on("mouseout", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",false);
				d3.selectAll(".rowLabel").classed("text-highlight",false);
				d3.selectAll(".colLabel").classed("text-highlight",false);
				d3.select("#tooltip1").classed("hidden", true);
			});
      		
      	var legend = svg.selectAll(".legend").data([minDist,minDist+0.1*gap,minDist+0.2*gap,minDist+0.3*gap,minDist+0.4*gap,minDist+0.5*gap,minDist+0.6*gap,minDist+0.7*gap,minDist+0.8*gap,minDist+0.9*gap,maxDist]).enter().append("g").attr("class", "legend");
		legend.append("rect").attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*2) - margin.top)
    		.attr("width", legendElementWidth).attr("height", cellSize)
    		.style("fill", function(d, i) { return colors[i]; });
    
    	legend.append("text").text(function(d) { return d3.format(".2f")(d); }).style("text-anchor", "left")
    		.attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*4)- margin.top);
	}
	
	function getConsensusItem(pathArr, idx)
	{
		var node = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) 
		{
			var path = pathArr[i];
			node.cnt ++;
			item = path[idx];
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			node.children[item].cnt ++;
		}
		
		var arr = Object.keys( node.children ).map(function ( key ) { return node.children[key].cnt; });
		var ratio = 100;
		if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
		maxItem = Object.keys(node.children)[arr.indexOf(Math.max.apply(Math,arr))];
		return node.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)";
	}
	
	function convertToHierarchy(pathArr) {
		var rootNode = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) {
			var path = pathArr[i];
			buildNodeRecursive(rootNode, path, 0);
		}
		return rootNode;
	}
	
	function buildNodeRecursive(node, path, idx) {
		if (idx < path.length) {
			node.cnt ++;
			item = path[idx];			
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			buildNodeRecursive(node.children[item], path, idx + 1);
		}
	}
	
	function getConsensusTaxonomy(currNode) {
		if(currNode.children && Object.keys(currNode.children).length > 0) {
			var arr = Object.keys( currNode.children ).map(function ( key ) { return currNode.children[key].cnt; });
			//console.log(arr + " : " +arr.length);
			//console.log(arr + " : " +Math.max.apply(Math,arr) +" : " + arr.indexOf(Math.max.apply(Math,arr)));
			//console.log(Math.max.apply(Math,arr) + " / " +math.sum(arr));
			
			var ratio = 100;
			if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
			
			maxItem = Object.keys(currNode.children)[arr.indexOf(Math.max.apply(Math,arr))];
			
			returnArr = [currNode.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)"];
			returnArr = returnArr.concat(getConsensusTaxonomy(currNode.children[maxItem]));
			return returnArr;
		}
		return [currNode.id+" (100%)"];
	}
	

</script>

</body>
</html>